package com.xbongbong.executor.command;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.parent.interfaces.FormDataService;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.saas.constant.ParameterConstant;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * FormDataService 工厂
 * @author 魏荣杰
 * @date 2020/12/30 15:27
 * @since
 * @version
 */
@Service("formDataServiceFactory")
public class FormDataServiceFactory {
    private static final Logger LOG = LoggerFactory.getLogger(FormDataServiceFactory.class);


    /**
     * CRM
     */
    @Resource
    private Map<Integer, FormDataService> businessAddMap;

    /**
     * 工厂
     * @param businessType
     * @param saasMark
     * @return
     */
    public FormDataService getFormDataService(Integer businessType, Integer saasMark) throws XbbException {
        FormDataService abstractFormDataService= null;
        if (Objects.equals(SaasMarkEnum.SAAS.getCode(), saasMark)) {
           abstractFormDataService = businessAddMap.get(businessType);
        } else if (Objects.equals(SaasMarkEnum.PAAS.getCode(), saasMark)) {
            abstractFormDataService = businessAddMap.get(XbbRefTypeEnum.PAAS.getCode());
        }
        if (Objects.isNull(abstractFormDataService)) {
            LOG.error("com.xbongbong.executor.command.FormDataServiceFactory：businessType="+businessType, "； saasMark="+saasMark);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, I18nStringConstant.NOT_EXIST, ParameterConstant.BUSINESS_TYPE);
        }
        return abstractFormDataService;
    }

}
